﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;

namespace Secams.controller
{
    class AppContext : Dictionary<String, object>
    {
        public const string VERSION = "v1.2.3 (20110829)";
        public const string DB_FILENAME = "Secams.mdb";

        protected static AppContext _instance = new AppContext();
        protected int _traceLevel = 0;

        protected string _appDataPath = null;
        protected string _startupPath = null;

        protected string _dataContextFilePath = "/data/";
        protected string _instructionContextDirPath = "/instructions/";
        protected string _scenariosContextDirPath = "/scenarios/";


        Settings _settings = new Settings();

        public static Font getDefaultFont(Font currentFont)
        {
            return new Font(currentFont.Name, 11, currentFont.Style, currentFont.Unit,
                currentFont.GdiCharSet, currentFont.GdiVerticalFont);
        }

        public static AppContext getInstance()
        {
            return _instance;
        }

        public int traceLevel
        {
            get { return _traceLevel; }
        }

        public string appDataPath
        {
            get { return _appDataPath; }
        }
        public string startupPath
        {
            get { return _startupPath; }
        }

        public string getDataFilePath(string dataFilename)
        {
            return _appDataPath + _dataContextFilePath + dataFilename; 
        }

        public string dbFilePath
        {
            get { return getDataFilePath(DB_FILENAME); }
        }

        public string instructionDirPath
        {
            get { return _startupPath+_instructionContextDirPath; }
        }

        public string getInstructionFilePath(string instFilename)
        {
            return instructionDirPath + instFilename;
        }

        public string scenariosDirPath
        {
            get { return _startupPath + _scenariosContextDirPath; }
        }

        public string getScenarioFilePath(string instFilename)
        {
            return scenariosDirPath + instFilename;
        }

        public Settings settings
        {
            get { return _settings; }
        }

        public void init(string startupPath, string applicationDataPath, string settingFile)
        {
            _startupPath = startupPath;
            _appDataPath = applicationDataPath;

            _settings.loadXml(startupPath + settingFile);
        }

        
        public void setProperty(string key, object val)
        {
            this[key] = val;
        }
        
        public object getProperty(string key, object defVal)
        {
            if (this.ContainsKey(key))
                return this[key];
            else return defVal;
        }

    }
}
